using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PyramidShadow
{
    public class menu 
    {
        //=========================================================

        // Create an instance of Texture2D that will
        // contain the background texture.
        Texture2D background;
 
        // Create a Rectangle that will define
        // the limits for the main game screen.

        //========================================================= 
        MouseState mbd; 
        MouseState Prevmbd;
        SpriteFont font;
        List<menuButton> mbs = new List<menuButton>();
        Game1 game;
        Vector2 draw = new Vector2(0, 0);

        public const byte NUM_MENUBUTTONS = 4;



        public menu(Game1 game)
        {
            int xoffset = (game.Window.ClientBounds.Width - 40) / NUM_MENUBUTTONS ;
            int yOffset = 50;
            int tmp = 20;
            mbs.Add(new menuButton(new Rectangle(tmp, yOffset, 100, 14), "Play"));
            tmp += xoffset;
            mbs.Add(new menuButton(new Rectangle(tmp, yOffset, 100, 14), "Load"));
            tmp += xoffset;
            mbs.Add(new menuButton(new Rectangle(tmp, yOffset, 100, 14), "About"));
            tmp += xoffset;
            mbs.Add(new menuButton(new Rectangle(tmp, yOffset, 100, 14), "Exit"));
            game.IsMouseVisible = true;              //x,y,width,height
            this.game = game;
        }


        public void LoadContent()
        {
            font = game.Content.Load<SpriteFont>("fonts/SpriteFont1");
            //=========================================================
            // Load the background content.
            background = game.Content.Load<Texture2D>("Textures\\background");
            
        }

        public void Update()
        {
            mbd = Mouse.GetState();

            foreach (menuButton m in mbs)
            {
                m.mouseOver(mbd);
                if (m.text == "Play" && m.selected == true && mbd.LeftButton == ButtonState.Pressed && Prevmbd.LeftButton == ButtonState.Released)
                {
                    game.gameState = GameState.play;
                }

                if (m.text == "Exit" && m.selected == true && mbd.LeftButton == ButtonState.Pressed && Prevmbd.LeftButton == ButtonState.Released)
                {
                    game.Exit();
                }

            }
            Prevmbd = mbd;
        }


        public void Draw(SpriteBatch spriteBatch)
        {
            
            //spriteBatch.Draw(background, game.Window.ClientBounds, Color.White); // Draw the background.
            spriteBatch.Draw(background, draw, Color.White);
            foreach (menuButton m in mbs)
            {
               m.Draw(spriteBatch, font);
            }
        }
    }
}
